#ifndef _HIT_H
#define _HIT_H

#include "Vectors.h"
#include "Ray.h"

class Material;

class Hit 
{
public:
	// CONSTRUCTOR & DESTRUCTOR
	Hit() { material = NULL; m_isTexture = false; t = FLT_MAX; }
	Hit(float _t, Material *m, Vec3f n) {
		t = _t; material = m; normal = n; m_isTexture = false;}
	Hit(const Hit &h) { 
		t = h.t; 
		material = h.material; 
		normal = h.normal; 
		intersectionPoint = h.intersectionPoint;
		m_textureColor = h.m_textureColor;
		m_isTexture = h.m_isTexture;}
	~Hit() {}

	// ACCESSORS
	float getT() const { return t; }
	Material* getMaterial() const { return material; }
	Vec3f getNormal() const { return normal; }
	Vec3f getIntersectionPoint() const { return intersectionPoint; }
	Vec3f getAmbientColor()const;
	Vec3f Shade(const Ray &ray,const Vec3f &dirToLight,const Vec3f &lightColor)const;

	// MODIFIER
	void set(float _t, Material *m, Vec3f n, const Ray &ray){
		t = _t; material = m; normal = n; 
		intersectionPoint = ray.pointAtParameter(t);
		m_isTexture = false;}
	void set(float _t, Material *m, Vec3f n, const Ray &ray,const Vec3f textureColor) {
		t = _t; material = m; normal = n; 
		intersectionPoint = ray.pointAtParameter(t);
		m_textureColor = textureColor;
		m_isTexture = true;}

private: 
	// REPRESENTATION
	float t;
	Material *material;
	Vec3f normal;
	Vec3f intersectionPoint;
	Vec3f m_textureColor;
	bool m_isTexture;
};

inline ostream &operator<<(ostream &os, const Hit &h) {
	os << "Hit <" <<h.getT()<<", "<<h.getNormal()<<">";
	return os;
}
#endif

